package com.uzhie.jt808.jt1078.entity;

import com.uzhie.jt808.JT808MsgBody;
import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.MyBuffer;

/**
 * 视频上传控制
 * Created by lilongfei on 2018/7/31.
 */
public class JT_9207 implements JT808MsgBody{

    //消息流水号
    int serialNumber;
    //上传控制
    byte control;

    public JT_9207(int serialNumber,int control){
        setSerialNumber(serialNumber);
        setControl(control);
    }

    public void setControl(int control){
        byte[] controls = BitConverter.GetBytes(control);
        setControl(controls[3]);
    }

    public int getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(int serialNumber) {
        this.serialNumber = serialNumber;
    }

    public byte getControl() {
        return control;
    }

    public void setControl(byte control) {
        this.control = control;
    }

    @Override
    public byte[] WriteToBytes() {
        MyBuffer buffer = new MyBuffer();
        byte[] serialNumbers = BitConverter.GetBytes(getSerialNumber());
        buffer.put(serialNumbers[2]);
        buffer.put(serialNumbers[3]);
        buffer.put(getControl());
        return buffer.array();
    }

    @Override
    public void ReadFromBytes(byte[] body) {
        MyBuffer buffer = new MyBuffer(body);
        int number = BitConverter.ToUInt32(buffer.gets(2),0);
        setSerialNumber(number);
        setControl(buffer.get());
    }
}
